// const arr = [{"name": "颜色", "specvs": [{"name": "白色", "img": ""}, {"name": "红色", "img": ""}]}, {
//   "name": "尺寸",
//   "specvs": [{"name": "iphone6", "img": ""}, {"name": "iphone6 plus", "img": ""}]
// }, {"name": "内存", "specvs": [{"name": "16G", "img": ""}, {"name": "32G", "img": ""}]}];

const arr = [
  {"name": "颜色", "specvs": [{"name": "白色", "img": ""}, {"name": "红色", "img": ""}]},
  // {
  //   "name": "尺寸",
  //   "specvs": [{"name": "iphone6", "img": ""}, {"name": "iphone6 plus", "img": ""}]
  // }
];

function get2dArr(arr){
  let tempArr = [];
  arr.forEach((v,i)=>{
    tempArr.push([]);
    v.specvs.forEach(val=>{
      tempArr[i].push(val.name);
    });
  });
  return tempArr;
}

function split2MultiArr(arr=[]){
  /*
   * @params
   * arr = [[1,2],[3,4],[5,6]...];
   * return
   *  [[1,3,5],[1,3,6],[2,3,5]...]
   * */
  function getTemp(arr1, arr2) {
    let temp = [];
    arr1.forEach((v, i)=> {
      arr2.forEach((val, j)=> {
        if (Array.isArray(v)) {
          temp.push([
            ...v,
            val
          ]);
        } else {
          temp.push([
            v,
            val
          ]);
        }
      })
    });
    return temp;
  }
  let temp = [];
  if(arr.length == 1){
    arr[0].forEach((v,i)=>{
      temp[i] = [v];
    });
  }
  for (let i = 1; i < arr.length; i++) {
    if (temp.length > 0) {
      temp = getTemp(temp, arr[i]);
    } else {
      temp = getTemp(arr[i - 1], arr[i]);
    }
  };

  return temp;
}

const tempArr = split2MultiArr(get2dArr(arr));

let result = [];
tempArr.forEach((v,i)=>{
  let item = {};
  v.forEach((val,j)=>{
    item[j] = val;
  });
  item.price = '';
  item.number = '';
  result.push(item);
});

console.log(result);

